package com.itchen.headline.service.impl;

import com.itchen.headline.dao.NewsUserDao;
import com.itchen.headline.dao.impl.NewsUserDaoImpl;
import com.itchen.headline.pojo.NewsUser;
import com.itchen.headline.service.NewsUserService;
import com.itchen.headline.util.MD5Util;

public class NewsUserServiceImpl implements NewsUserService {
    private NewsUserDao newsUserDao = new NewsUserDaoImpl();
    @Override
    public NewsUser findByUsername(String username) {
        return newsUserDao.findByUsername(username);
    }

    @Override
    public NewsUser findByUid(Integer userId) {
        return newsUserDao.findByUid(userId);
    }

    @Override
    public Integer registUser(NewsUser registUser) {
        // 在这里将用户输入的密码转为密文密码
        // registUser.getUserPwd()    获取用户密码
        // MD5Util.encrypt()          将密码转为密文密码
        // registUser.setUserPwd()    将密文密码设置封装到registUser对象中
        registUser.setUserPwd(MD5Util.encrypt(registUser.getUserPwd()));
        return newsUserDao.insertUser(registUser);
    }
}
